package com.lxb.oss.controller;

import com.lxb.commonutils.R;
import com.lxb.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * oss存储
 * @author xuebin.li
 * @createTime 2022/10/26 23:45
 */
@Api(description = "阿里云文件管理")
@RestController
@RequestMapping("/eduoss/fileoss")
//@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    @ApiOperation(value = "文件上传")
    @PostMapping("/upfile")
    public R upLoadOssFile(
            @ApiParam(name = "file",value = "文件",required = true)
            @RequestParam("file") MultipartFile file){
        //获得上传文件
        String fileUrl = ossService.upLoadFileAvatar(file);
        //返回上传到oss的网页路径
        return R.ok().data("url",fileUrl);
    }
}
